<?php

namespace App\Http\Requests;

use App\Commons\Http\Requests\BaseRequest as Request;
use Arr;

abstract class BaseRequest extends Request
{
    private $_ruleConfigs;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 定义验证规则
     * key, // 默认全局规则
     * key => 1, // 默认全局规则，1为默认值
     * key => ['rule' => 'required', default => 1],
     * key => ['rule' => 'required|*', default => 1], // *号指继承全局规则
     * key => ['rule' => 'required|*|integer', default => 1], // *可调理继承顺序
     * key => ['rule' => 'required', default => 1, type => 'int'], // 转换为int型
     * key => ['rule' => 'required', default => 1, type => 'int', 'as' => 'otherKey'], // 变量名替换为otherKey
     *
     * @return [type] [description]
     */
    // abstract protected function rule() : array;

    /**
     * 全局验证规则，如果定义了 $_rules 相同规则 ，将会覆盖全局规则
     *
     * @return [type] [description]
     */
    protected function globalRules()
    {
        return [
            'mobile' => 'required|phone',
            'password' => 'required|min:6',
            'name' => 'string|max:40',
            'gender' => 'integer',
            'size' => 'integer',
            'keywords' => 'string',
            'id' => 'integer',
            'page' => 'integer',
            'phone' => 'phone',
            'code' => 'string',
            'type' => 'integer',
            'token' => 'string',
        ];
    }

    /**
     * 获取验证错误的自定义属性
     * 在错误消息里 :email 将会替换为 email address
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'email' => 'email address',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     *
     * @return array
     */
    public function messages()
    {
        return [
            'username.required' => '缺少用户名',
            'password.required' => '缺少密码',
            'mobile.required' => '手机号不能为空',
            'code.required' => '请输入验证码',
            'password.min' => '密码长度不小于:min个字符',
            'required' => '缺少参数 :attribute',
            'integer' => ':attribute 要求是数字',
            'numeric' => ':attribute 要求是数字',
            'min' => ':attribute 要求不小于:min',
            'max' => ':attribute 字符串超出长度 :max',
            'phone' => '手机号不正确',
            'in' => ':attribute 参数取值必须为 :values',
            'between' => ':attribute 参数范围必须在 :min - :max',
            'boolean' => ':attribute 参数取值必须为0或1',
            'date_format' => ':attribute 日期格式不正确 :format',
            'card_no.required' => '银行卡不能为空',
            'card_no' => '银行卡号不正确',
            'id_card' => '身份证不正确',

        ];
    }
}
